/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.localapp;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.suspend.b.b.d;
import com.qihoo.gamecenter.sdk.suspend.b.b.e;
import com.qihoo.gamecenter.sdk.suspend.b.b.h;
import com.qihoo.gamecenter.sdk.suspend.b.b.j;
import com.qihoo.gamecenter.sdk.suspend.remote.QRemoteService;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class c {
    private static j b;
    static d a = new d() {
        protected void a(e parame) {}
    };

    public static void a(Context paramContext) {
        List localList = b(paramContext);
        ArrayList localArrayList = new ArrayList();
        JSONObject localJSONObject = null;
        JSONArray localJSONArray = new JSONArray();
        try {
            for (int i = 0; i < localList.size(); ++i) {
                b localb = (b) localList.get(i);
                localJSONObject = new JSONObject();
                localJSONObject.put("pkgname", localb.e());
                localJSONObject.put("vers", localb.d());
                localJSONObject.put("size", localb.c());
                localJSONObject.put("sdkkey", localb.a());
                localJSONObject.put("sdkid", localb.b());
                localJSONArray.put(localJSONObject);
                if (!("com.qihoo.gameunion".equals(localb.e())))
                    continue;
                com.qihoo.gamecenter.sdk.suspend.c.a.a(paramContext, true);
                com.qihoo.gamecenter.sdk.suspend.c.a.b(paramContext, localb.d());
            }
            com.qihoo.gamecenter.sdk.suspend.b.b.a("LocalAppManager", "APP JSON: " + localJSONArray.toString());
            h.a(localArrayList, "ks", localJSONArray.toString());
        } catch (JSONException localJSONException) {
            localJSONException.printStackTrace();
        }
        String str = com.qihoo.gamecenter.sdk.suspend.b.d.a.m;
        try {
            str = com.qihoo.gamecenter.sdk.suspend.b.d.a.m
                    + QRemoteService.a().b(com.qihoo.gamecenter.sdk.suspend.remote.b.b().c());
        } catch (RemoteException localRemoteException) {
            localRemoteException.printStackTrace();
        }
        b = new j(paramContext, str, a, true);
        com.qihoo.gamecenter.sdk.suspend.b.b.a("LocalAppManager",
                "--------------------------------prepare to upload apps to server.--------------------------");
        b.execute(new List[] { localArrayList });
    }

    public static List b(Context paramContext) {
        List localList = c(paramContext);
        ArrayList localArrayList = new ArrayList();
        for (int i = 0; i < localList.size(); ++i) {
            b localb = new b();
            PackageInfo localPackageInfo = (PackageInfo) localList.get(i);
            String str1 = localPackageInfo.packageName;
            if ((localPackageInfo.applicationInfo.flags & 0x1) != 0)
                continue;
            String str2 = localPackageInfo.versionName;
            int j = localPackageInfo.versionCode;
            String str3 = localPackageInfo.applicationInfo.loadLabel(paramContext.getPackageManager()).toString();
            String str4 = localPackageInfo.applicationInfo.publicSourceDir;
            long l = new File(str4).length();
            localb.a(l);
            localb.f(str1);
            localb.e(str3);
            localb.a(j);
            localb.d(str2);
            localb.c(localPackageInfo.applicationInfo.sourceDir);
            Bundle localBundle = localPackageInfo.applicationInfo.metaData;
            if ((localBundle != null) && (!(TextUtils.isEmpty(localBundle.getString("QHOPENSDK_APPKEY")))))
                localb.a(localBundle.getString("QHOPENSDK_APPKEY"));
            if ((localBundle != null) && (localBundle.getInt("QHOPENSDK_APPID") > 0))
                localb.b(localBundle.getInt("QHOPENSDK_APPID"));
            com.qihoo.gamecenter.sdk.suspend.b.b.a("LocalAppManager", "packagename:" + str1 + "------appKey----"
                    + localb.a() + "------appId----" + localb.b());
            localArrayList.add(localb);
        }
        return localArrayList;
    }

    private static List c(Context paramContext) {
        PackageManager localPackageManager = paramContext.getPackageManager();
        List localList = localPackageManager.getInstalledPackages(128);
        return localList;
    }

    public static b a(Context paramContext, String paramString) {
        List localList = c(paramContext);
        b localb = new b();
        for (int i = 0; i < localList.size(); ++i) {
            PackageInfo localPackageInfo = (PackageInfo) localList.get(i);
            String str1 = localPackageInfo.packageName;
            if ((!(str1.equals(paramString))) || ((localPackageInfo.applicationInfo.flags & 0x1) != 0))
                continue;
            String str2 = localPackageInfo.versionName;
            int j = localPackageInfo.versionCode;
            String str3 = localPackageInfo.applicationInfo.loadLabel(paramContext.getPackageManager()).toString();
            localb.f(str1);
            localb.e(str3);
            String str4 = localPackageInfo.applicationInfo.publicSourceDir;
            long l = new File(str4).length();
            localb.a(l);
            localb.a(j);
            localb.d(str2);
            localb.c(localPackageInfo.applicationInfo.sourceDir);
            Bundle localBundle = localPackageInfo.applicationInfo.metaData;
            if ((localBundle != null) && (!(TextUtils.isEmpty(localBundle.getString("QHOPENSDK_APPKEY")))))
                localb.a(localBundle.getString("QHOPENSDK_APPKEY"));
            if ((localBundle != null) && (localBundle.getInt("QHOPENSDK_APPID") > 0))
                localb.b(localBundle.getInt("QHOPENSDK_APPID"));
            com.qihoo.gamecenter.sdk.suspend.b.b.a("LocalAppManager",
                    "metaData == null  is " + (localBundle == null) + "----------packagename:" + str1
                            + "------appKey----" + localb.a() + "------appId----" + localb.b());
        }
        return localb;
    }
}